package com.java.gamePackeg;

import java.util.Objects;

public class Product {
    //商品ID
    private int proId;
    //商品名称
    private String name;
    //最低价格
    private int minPrice;
    //最高价格
    private int maxPrice;
    //当前价格
    private Integer nowPrice;

    public Product(int proId, String name, int minPrice, int maxPrice) {
        this.proId = proId;
        this.name = name;
        this.minPrice = minPrice;
        this.maxPrice = maxPrice;
    }

    public int getProId() {
        return proId;
    }

    public void setProId(int proId) {
        this.proId = proId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getMinPrice() {
        return minPrice;
    }

    public void setMinPrice(int minPrice) {
        this.minPrice = minPrice;
    }

    public int getMaxPrice() {
        return maxPrice;
    }

    public void setMaxPrice(int maxPrice) {
        this.maxPrice = maxPrice;
    }

    public Integer getNowPrice() {
        return nowPrice;
    }

    public void setNowPrice(Integer nowPrice) {
        this.nowPrice = nowPrice;
    }

    @Override
    public String toString() {
        return name + "   " + nowPrice;
    }

    /**
     * 随机当前商品价格
     */
    public void randomNowPrice() {
        this.nowPrice = (int) (Math.random() * (this.maxPrice - this.minPrice) + this.minPrice);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Product)) return false;
        Product product = (Product) o;
        return getProId() == product.getProId();
    }

    @Override
    public int hashCode() {
        return Objects.hash(getProId(), getName(), getMinPrice(), getMaxPrice());
    }
}
